from rest_framework import serializers


from .models import Area

class AreaSerializer(serializers.ModelSerializer):
    """如果是查询所有的省， 用此序列化器处理数据"""
    class Meta:
        model = Area
        fields = ['id', 'name']

class SubsAreaSerializer(serializers.ModelSerializer):
    """查询单个省或市时，使用此序列化器"""
    subs = AreaSerializer(many=True)
    class Meta:
        model = Area
        fields = ['id', 'name', 'subs']

